﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nachos.Machine
{
    public class Timer
    {
        /// <summary>
        /// set if we need to use a random timeout delay
        /// </summary>
        private bool randomize;
        private bool disable;

        private void SetInterrupt()
        {
            if (!disable)
            {
                int delay = TimerTicks;

                if (randomize)
                {
                    delay = 1 + (RandomNumber() % (TimerTicks * 2));
                }
                // schedule the next timer device interrupt
                kernel.Interrupt.Schedule(this, delay, TimerInt);
            }
        }

        public void Disable() 
        {
            disable = true;
        }
    }
}
